package handler

import (
	"context"
	"github.com/gin-gonic/gin"
	"internal/api/logic/signin"
	"internal/store/redis"
)

func SignedHandler(c *gin.Context) {
	ctx := context.Background()
	HashKey := c.Query("expireTimeKey")
	if HashKey == "" {
		c.JSON(200, gin.H{
			"code": 400,
			"msg":  "expire time key is null",
		})
		return
	}
	if err := redis.GetRedisConn().Get(ctx, HashKey).Err(); err != nil {
		c.JSON(200, gin.H{
			"code": -1,
			"msg":  "The signed QR code has expired",
		})
		return
	}
	// 执行签到的业务逻辑
	err := signin.SignIn()
	if err != nil {
		c.JSON(200, gin.H{
			"code": -1,
			"msg":  "sign in failed",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "Success",
	})
}
